cmake_minimum_required(VERSION 2.6)

project(VirtualMine)
set(OGRE_DIR $ENV{OGRE_HOME})
set(QT_DIR $ENV{QTDIR})
STRING(REGEX REPLACE "\\\\" "/" OGRE_DIR ${OGRE_DIR}) 
if(WIN32)
	set(CMAKE_MODULE_PATH "${OGRE_DIR}/CMake/;${CMAKE_MODULE_PATH}")
	set(OGRE_INCLUDE_DIRS  $ENV{OGRE_HOME}/include  $ENV{OGRE_HOME}/include/OGRE)
	set(OGRE_BOOST_INCLUDEPATH $ENV{OGRE_HOME}/boost_1_44/)
	set(QT_INCLUDEPATH ${QT_DIR}/include)
	set(QT_LIBPATH ${QT_DIR}/lib)
endif(WIN32)

find_package(OGRE REQUIRED)

if(NOT "${OGRE_VERSION_NAME}" STREQUAL "Cthugha")
  message(SEND_ERROR "You need Ogre 1.7 Cthugha to build this.")
endif()


macro(copy_release_dir INPUT INPUTDIR)
  if (EXISTS ${INPUTDIR}/${INPUT})
    if (MINGW OR NMAKE)
      configure_file(${INPUTDIR}/${INPUT} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${INPUT} COPYONLY)
	else ()
      configure_file(${INPUTDIR}/${INPUT} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/release/${INPUT} COPYONLY)
#      configure_file(${INPUTDIR}/${INPUT} #${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/relwithdebinfo/${INPUT} COPYONLY)
#      configure_file(${INPUTDIR}/${INPUT} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/minsizerel/#${INPUT} COPYONLY)
	endif ()
  endif ()
endmacro ()

macro(OGRE_copy_release INPUT)
	copy_release_dir(${INPUT} ${OGRE_PLUGIN_DIR_REL})
endmacro()
macro(QT_copy_release INPUT)
	copy_release_dir(${INPUT} ${QT_BINARY_DIR})
endmacro()

macro(copy_debug_dir INPUT INPUTDIR)
  if (EXISTS ${INPUTDIR}/${INPUT})
    if (MINGW OR NMAKE)
      configure_file(${INPUTDIR}/${INPUT} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${INPUT} COPYONLY)
	else ()
      configure_file(${INPUTDIR}/${INPUT} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/debug/${INPUT} COPYONLY)
	endif ()
  endif ()
endmacro()

macro(OGRE_copy_debug INPUT)
	copy_debug_dir(${INPUT} ${OGRE_PLUGIN_DIR_DBG})
endmacro()

macro(QT_copy_debug INPUT)
	copy_debug_dir(${INPUT} ${QT_BINARY_DIR})
endmacro()
# Specify build paths
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")


set(PROJECT_TEMPLATES_DIR "${PROJECT_SOURCE_DIR}/CMake/Templates")
set(PROJECT_WORK_DIR ${PROJECT_BINARY_DIR})

link_directories(	
		${QT_DIR}/lib 
		${OGRE_DIR}/lib/debug
		${OGRE_DIR}/lib/release
		${OGRE_DIR}/boost_1_44/lib
		${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
	 )


	copy_release_dir(SdkTrays.zip ${PROJECT_SOURCE_DIR}/media)
	copy_debug_dir(SdkTrays.zip ${PROJECT_SOURCE_DIR}/media)
	
	copy_release_dir(old_fence.jpg ${PROJECT_SOURCE_DIR}/media)
	copy_debug_dir(old_fence.jpg ${PROJECT_SOURCE_DIR}/media)
	
	copy_release_dir(red_brick.jpg ${PROJECT_SOURCE_DIR}/media)
	copy_debug_dir(red_brick.jpg ${PROJECT_SOURCE_DIR}/media)
	
	copy_release_dir(Examples.material ${PROJECT_SOURCE_DIR}/media)
	copy_debug_dir(Examples.material ${PROJECT_SOURCE_DIR}/media)

	copy_release_dir(samplefont.fontdef ${PROJECT_SOURCE_DIR}/media)
	copy_debug_dir(samplefont.fontdef ${PROJECT_SOURCE_DIR}/media)

	copy_release_dir(bluehigh.ttf ${PROJECT_SOURCE_DIR}/media)
	copy_debug_dir(bluehigh.ttf ${PROJECT_SOURCE_DIR}/media)
	

	copy_release_dir(resources.cfg ${PROJECT_SOURCE_DIR}/media)
	copy_debug_dir(resources_d.cfg ${PROJECT_SOURCE_DIR}/media)


function(create_vcproj_userfile TARGETNAME)
  if (MSVC)
	if (MSVC_VERSION  EQUAL 1600)
	   configure_file(
	  ${PROJECT_TEMPLATES_DIR}/VisualStudioUserFile.vcxproj.user.in
	  ${CMAKE_CURRENT_BINARY_DIR}/${TARGETNAME}.vcxproj.user
	  @ONLY
	)
	else()
	  configure_file(
	  ${PROJECT_TEMPLATES_DIR}/VisualStudioUserFile.vcproj.user.in
	  ${CMAKE_CURRENT_BINARY_DIR}/${TARGETNAME}.vcproj.user
	  @ONLY
	)
	endif()
  endif ()
 endfunction(create_vcproj_userfile)



add_subdirectory(Procedural)
add_subdirectory(QOgre)
